package cn.map.hashmap;

import java.util.*;

public class Demo12 {
    public static void main(String[] args) {
        /*
            某个班级80名学生，现在需要组成秋游活动，
            班长提供了四个景点依次是（A、B、C、D）,
            每个学生只能选择一个景点，请统计出最终哪个景点想去的人数最多。
        */
        String[] arr = {"A", "B", "C", "D"};
        Map<String,Integer> hm = new HashMap<>();
        Random r = new Random();
        hm.put("A", 0);
        hm.put("B", 0);
        hm.put("C", 0);
        hm.put("D", 0);
        for (int i = 0; i < 80; i++) {
            int index = r.nextInt(arr.length);
            hm.put(arr[index], hm.get(arr[index]) + 1);
        }
        //3.求最大值
        //4.判断哪个景点的次数跟最大值一样，如果一样，打印出来
        //3.求最大值
        int max = 0;
        String addr = null;
        Set<Map.Entry<String, Integer>> entries1 = hm.entrySet();
        for (Map.Entry<String, Integer> entry : entries1) {
            int count = entry.getValue();
            if(count > max){
                max = count;
                addr = entry.getKey();
            }
        }

        // Set<Map.Entry<String, Integer>> entries = hm.entrySet();
        // for (Map.Entry<String, Integer> entry : entries) {
        //     int count = entry.getValue();
        //     if(count > max){
        //         max = count;
        //     }
        // }



        System.out.println(addr);
        System.out.println(max);

        hm.forEach((k,v)-> System.out.println(k + ":" + v));
    }
}
